<template>
	<view class="homePage">
		<!-- 轮播图 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
			<swiper-item v-for="item in swipers" :key = "item.id">
					<image :src="item.img" mode=""></image>
			</swiper-item>
		</swiper>
		<!-- 导航条 -->
		<view class="nav">
			<view class="nav_item" v-for="item in navs" :key="item.id" @click="navItemClick(item.path)">
				<view class="nav_pic">
					<image :src="item.src" mode=""></image>
				</view>
				<view class="nav_text">{{item.title}}</view>
			</view>
		</view>
		<!-- 推荐商品 -->
		<view class="goods">
			<view class="goods_recommend">推荐商品</view>
			<goods-list :goods="goods" @goodsItemClick="goGoodsDetail"></goods-list>
		</view>
		
	</view>
</template>

<script>
	import goodsList from '../../components/goods-list/goods-list.vue'
	export default {
		data() {
			return {
				swipers: [],
				goods:[],
				navs: [
					{
						id:1,
						title: '黑马超市',
						src:"../../static/nav_pic/supermarket.png",
						path:"../supermarket/supermarket"
					},
					{
						id:2,
						title: '联系我们',
						src:"../../static/nav_pic/contact.png",
						path:"../contact/contact"
					},
					{
						id:3,
						title: '社区图片',
						src:"../../static/nav_pic/picture.png",
						path:"../picture/picture"
					},
					{
						id:4,
						title: '学习视频',
						src:"../../static/nav_pic/video.png",
						path:"../video/video"
					}
				],
				
			}
		},
		onLoad() {
			this.getSwiperData()
			this.getHotGoods()
		},
		methods: {
			//获取轮播图数据
			async getSwiperData(){
				let res = await this.$myRequest({
					url:"/api/getlunbo"
				})
				this.swipers = res.data.message
			},
			//获取热门商品的数据
			async getHotGoods(){
				let res = await this.$myRequest({
					url:"/api/getgoods?pageindex=1"
				})
				this.goods = res.data.message
				
			},
			//导航条的点击跳转事件
			navItemClick(path){
				uni.navigateTo({
					url:path
				})
			},
			//跳转到商品详情页面
			goGoodsDetail(id){
				uni.navigateTo({
					url: '../goodsDetail/goodsDetail?id='+id
				})
			}
		},
		components:{
			goodsList:goodsList
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
		width: 100%;
		background:#e6e6e6;
		.homePage{
			height: 100%;
			width: 100%;
		}
	}
	swiper{
		width: 750rpx;
		height: 380rpx;
		image{
			height: 100%;
			width: 100%;
		}
	}
	.nav{
		height: 200rpx;
		width: 100%;
		padding-top: 20rpx;
		display: flex;
		background-color: #ffffff;
		.nav_item{			
			width: 25%;
			.nav_pic{
				width: 120rpx;
				height: 120rpx;
				border-radius: 60rpx;
				text-align: center;
				margin: 0 auto;
				background-color: #b50e03;
				image{
					height: 100%;
					width: 100%;
					display: block;
					transform: scale(0.7);
				}
			}
			.nav_text{
				margin-top: 20rpx;
				text-align: center;
				font-size: 30rpx;
				font-weight: bold;
			}
		}
	}
	.goods{
		width: 100%;
		.goods_recommend{
			height: 50px;
			line-height: 50px;
			color: #b50e03;
			text-align: center;			
			background: #fff;
			margin: 7rpx 0;
			letter-spacing:40rpx
		}
	}
</style>
